package io.bitmax.library.utils;

/**
 * Created by gongdongyang on 2018/9/18.
 */

public class Assert {

    private static final String MESSAGE_FORMAT = "\"%s\" 参数不能为空.";

    /**
     * notNull:判断对象是否为空. <br/>
     * <p>
     * 空则抛出NullPointerException异常
     * </p>
     *
     * @param object
     * @param argName
     * @author adison
     */
    public static void checkNotNull(Object object, String argName) {
        if (object == null && LogUtils.isDebuggable()) {

            throw new NullPointerException(String.format(MESSAGE_FORMAT, argName));
        }
    }

    public static void judge(boolean bool) {
        if (bool || !LogUtils.isDebuggable())
            return;

        RuntimeException error = new RuntimeException();
        StackTraceElement[] elements = error.getStackTrace();
        judge(bool, "Assert error! Class:" + elements[1].getClassName()
                + " Method:" + elements[1].getMethodName()
                + " Line:" + elements[1].getLineNumber());
    }

    public static void judge(boolean bool, String hint) {
        if (bool || !LogUtils.isDebuggable())
            return;

        throw new RuntimeException(hint);
    }
}
